
const MyPromise = require("./MyPromise")
// 创建实例
let promise = new MyPromise((resolve, reject) => {
  // setTimeout(() => {
  //   // resolve("成功 2000")
  //   reject("失败 2000")
  // }, 2000);
  
  // throw new Error("executor error")
  // resolve("成功")
  // reject("失败")
})


function p1() {
  return new MyPromise((resolve, reject) => {
    setTimeout(() => {
      resolve("p1")
    }, 2000);
  })
}
function p2() {
  return new MyPromise((resolve, reject) => {
    // resolve("p2 resolve")
    reject("p2 reject")
  })
}

// promise.then().then().then(value => {
//   console.log(value)
// }, reason => {
//   console.log(reason);
// })

// MyPromise.all(['a', p1(), p2(), 'b']).then(value => {
//   console.log(value)
// }, reason => {
//   console.log(reason)
// })

// MyPromise.resolve(100).then(value => { console.log(value) })
// MyPromise.resolve(p1()).then(value => { console.log(value) })

p2().then(value => {
  console.log(value)
}).catch(error => {
  console.log(error)
})